package com.py.schedule.controller;

import com.py.model.common.dtos.ResponseResult;
import com.py.model.schedule.dtos.Task;
import com.py.schedule.service.TaskService;
import com.py.schedule.service.impl.TaskServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2022/11/14 11:00
 * @Version 1.0
 */
@RestController
@RequestMapping("/task")
public class TaskController {

    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskServiceImpl taskServiceImpl;

    @PostMapping("/add")
    public ResponseResult addTask(@RequestBody Task task){
        return taskService.addTask(task);
    }


    /**
     * 定时拉取list缓存中的文章数据执行审核
     */
    @GetMapping("/poll/{type}/{priority}")
    public ResponseResult getTask(@PathVariable("type") int type,@PathVariable("priority")  int priority){
        return ResponseResult.okResult(taskService.poll(type,priority));
    }

    /**
     * 测试接口
     * @param type
     * @return
     */
    @GetMapping("/test")
    public String test(Integer type){
        if(type == 1){
            taskServiceImpl.loadDataToZset();
        }else {
            taskServiceImpl.pushExecTask();
        }
        return "OK";
    }
}